function pushup()  
{   
		document.getElementById("accountId0").value="";  
		document.getElementById("DRamount0").value="";  
		document.getElementById("description0").value="";  
		{% for tax in all_expense_taxes %}
				document.getElementById("{{tax['shortname']}}0").value="";
		{% endfor %}
		{% for tax in last_expense_taxes %}
				document.getElementById("{{tax['shortname']}}0").value="";
		{% endfor %}
}
function check_value()
{
		var accountId0 = document.getElementById('accountId0').value;
		var DRamount0 = document.getElementById('DRamount0').value;
		var description0 = document.getElementById('description0').value;  
		var bool = true;
		
		if(accountId0=="" || DRamount0=="" || description0=="")
		{               
				bool = false;
		}
		{% for tax in all_expense_taxes %}
				if(document.getElementById("{{tax['shortname']}}0").value == "")
				{
						bool = false;
				}
		{% endfor %}
		if(DRamount0!="" && isNaN(parseFloat(DRamount0)))
		{
				document.getElementById('DRamount0').value = "";
				bool = false;
		}     
		{% for tax in all_expense_taxes %}
				if(document.getElementById("{{tax['shortname']}}0").value!="" && isNaN(parseFloat(document.getElementById("{{tax['shortname']}}0").value)))
				{
						document.getElementById("{{tax['shortname']}}0").value = "";
						bool = false;
				}
		{% endfor %}
		{% for tax in last_expense_taxes %}
				if(document.getElementById("{{tax['shortname']}}0").value!="" && isNaN(parseFloat(document.getElementById("{{tax['shortname']}}0").value)))
				{
						document.getElementById("{{tax['shortname']}}0").value = "";
						bool = false;
				}
		{% endfor %}
		return bool;
}

var i = 1;
function add_row(){
		if(check_value()){		
				var dl = document.createElement('dl');
				dl.setAttribute('class','fin-form2'); 
				dl.setAttribute('className','fin-form2'); 
				dl.setAttribute('id','item'+i);
				
				var dd = document.createElement('dd');
				var account_id = document.getElementById('accountId0').value;
				dd.innerHTML='<input type="hidden" name="accountId" value="'+account_id+'"/><a href="/bin/finance.py/show_account_details?a='+account_id+'">'+account_id+'</a>';
				dl.appendChild(dd);
				
				var dd = document.createElement('dd');
				var dr_amount = document.getElementById('DRamount0').value;
				dd.innerHTML = '<input type="hidden" name="DRamount" value="'+dr_amount+'"/>'+dr_amount;
				dl.appendChild(dd);
				
				var dd = document.createElement('dd');
				var description = document.getElementById('description0').value;
				dd.innerHTML='<div style="display:none"><textarea name="description">'+description+'</textarea></div>'+escapeHTML(description);
				dl.appendChild(dd);	
				
				{% for tax in all_expense_taxes %}
						var dd = document.createElement('dd');
						var tax_value = document.getElementById("{{tax['shortname']}}0").value;
						dd.innerHTML='<input type="hidden" name="{{tax["shortname"]}}" value="'+tax_value+'"/>'+tax_value;
						dl.appendChild(dd);
				{% endfor %}
				{% for tax in last_expense_taxes %}
						var dt = document.createElement('dt');
						var tax_value = document.getElementById("{{tax['shortname']}}0").value;
						dt.innerHTML='<input type="hidden" name="{{tax["shortname"]}}" value="'+tax_value+'"/>'+tax_value;
						dl.appendChild(dt);
				{% endfor %}
				var obj=document.getElementById('table2');
				obj.appendChild(dl);
				i++;
				show_submit();
				pushup();
		}
}
function show_submit(){		
		var submit_button=document.getElementById('submit_button');
		if(i>1){
			submit_button.style.display='';
		}else{
			submit_button.style.display='none';
		}
}
